package cc.dowell.controller;

import cc.dowell.enums.HttpCodeEnum;
import cc.dowell.pojo.User;
import cc.dowell.service.UserService;
import cc.dowell.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public R<?> register(@RequestBody User user) {
        return R.success(userService.register(user));
    }

    @PostMapping("/login")
    public R<?> login(@RequestBody User user) {
        return userService.login(user);
    }

    @PostMapping("/updatePassword")
    public R<?> updatePassword(@RequestBody User user) {
        Boolean b = userService.changePassword(user);
        if(b){
            return R.success();
        }
        return R.error(HttpCodeEnum.UPDATE_FAIl);
    }

    @PostMapping("/checkOldPassword")
    public R<?> checkOldPassword(@RequestBody User user){
        Boolean b = userService.checkOldPassword(user);
        if(b){
            return R.success();
        }
        return R.error(HttpCodeEnum.WRONG_OLD_PWD);
    }

}
